/*     */ package com.cr.common.utils;
/*     */ 
/*     */ import com.cr.common.core.text.StrFormatter;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Collection;
/*     */ import java.util.HashSet;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */
/*     */ import org.apache.commons.lang3.StringUtils;
import org.springframework.util.AntPathMatcher;
/*     */ @SuppressWarnings("unchecked")
/*     */ public class MyStringUtils extends StringUtils {
/*     */   private static final String NULLSTR = "";
/*     */   
/*     */   private static final char SEPARATOR = '_';
/*     */   
/*     */   public static <T> T nvl(T value, T defaultValue) {
/*  34 */     return (value != null) ? value : defaultValue;
/*     */   }
/*     */   
/*     */   public static boolean isEmpty(Collection<?> coll) {
/*  45 */     return (isNull(coll) || coll.isEmpty());
/*     */   }
/*     */   
/*     */   public static boolean isNotEmpty(Collection<?> coll) {
/*  56 */     return !isEmpty(coll);
/*     */   }
/*     */   
/*     */   public static boolean isEmpty(Object[] objects) {
/*  67 */     return (isNull(objects) || objects.length == 0);
/*     */   }
/*     */   
/*     */   public static boolean isNotEmpty(Object[] objects) {
/*  78 */     return !isEmpty(objects);
/*     */   }
/*     */   
/*     */   public static boolean isEmpty(Map<?, ?> map) {
/*  89 */     return (isNull(map) || map.isEmpty());
/*     */   }
/*     */   
/*     */   public static boolean isNotEmpty(Map<?, ?> map) {
/* 100 */     return !isEmpty(map);
/*     */   }
/*     */   
/*     */   public static boolean isEmpty(String str) {
/* 111 */     return (isNull(str) || "".equals(str.trim()));
/*     */   }
/*     */   
/*     */   public static boolean isNotEmpty(String str) {
/* 122 */     return !isEmpty(str);
/*     */   }
/*     */   
/*     */   public static boolean isNull(Object object) {
/* 133 */     return (object == null);
/*     */   }
/*     */   
/*     */   public static boolean isNotNull(Object object) {
/* 144 */     return !isNull(object);
/*     */   }
/*     */   
/*     */   public static boolean isArray(Object object) {
/* 155 */     return (isNotNull(object) && object.getClass().isArray());
/*     */   }
/*     */   
/*     */   public static String trim(String str) {
/* 163 */     return (str == null) ? "" : str.trim();
/*     */   }
/*     */   
/*     */   public static String substring(String str, int start) {
/* 175 */     if (str == null)
/* 177 */       return ""; 
/* 180 */     if (start < 0)
/* 182 */       start = str.length() + start; 
/* 185 */     if (start < 0)
/* 187 */       start = 0; 
/* 189 */     if (start > str.length())
/* 191 */       return ""; 
/* 194 */     return str.substring(start);
/*     */   }
/*     */   
/*     */   public static String substring(String str, int start, int end) {
/* 207 */     if (str == null)
/* 209 */       return ""; 
/* 212 */     if (end < 0)
/* 214 */       end = str.length() + end; 
/* 216 */     if (start < 0)
/* 218 */       start = str.length() + start; 
/* 221 */     if (end > str.length())
/* 223 */       end = str.length(); 
/* 226 */     if (start > end)
/* 228 */       return ""; 
/* 231 */     if (start < 0)
/* 233 */       start = 0; 
/* 235 */     if (end < 0)
/* 237 */       end = 0; 
/* 240 */     return str.substring(start, end);
/*     */   }
/*     */   
/*     */   public static String format(String template, Object... params) {
/* 258 */     if (isEmpty(params) || isEmpty(template))
/* 260 */       return template; 
/* 262 */     return StrFormatter.format(template, params);
/*     */   }
/*     */   
/*     */   public static boolean ishttp(String link) {
/* 273 */     return startsWithAny(link, new CharSequence[] { "http://", "https://" });
/*     */   }
/*     */   
/*     */   public static final Set<String> str2Set(String str, String sep) {
/* 285 */     return new HashSet<>(str2List(str, sep, true, false));
/*     */   }
/*     */   
/*     */   public static final List<String> str2List(String str, String sep, boolean filterBlank, boolean trim) {
/* 299 */     List<String> list = new ArrayList<>();
/* 300 */     if (isEmpty(str))
/* 302 */       return list; 
/* 306 */     if (filterBlank && isBlank(str))
/* 308 */       return list; 
/* 310 */     String[] split = str.split(sep);
/* 311 */     for (String string : split) {
/* 313 */       if (!filterBlank || !isBlank(string)) {
/* 317 */         if (trim)
/* 319 */           string = string.trim(); 
/* 321 */         list.add(string);
/*     */       } 
/*     */     } 
/* 324 */     return list;
/*     */   }
/*     */   
/*     */   public static boolean containsAnyIgnoreCase(CharSequence cs, CharSequence... searchCharSequences) {
/* 336 */     if (isEmpty(cs) || isEmpty((Object[])searchCharSequences))
/* 338 */       return false; 
/* 340 */     for (CharSequence testStr : searchCharSequences) {
/* 342 */       if (containsIgnoreCase(cs, testStr))
/* 344 */         return true; 
/*     */     } 
/* 347 */     return false;
/*     */   }
/*     */   
/*     */   public static String toUnderScoreCase(String str) {
/* 355 */     if (str == null)
/* 357 */       return null; 
/* 359 */     StringBuilder sb = new StringBuilder();
/* 361 */     boolean preCharIsUpperCase = true;
/* 363 */     boolean curreCharIsUpperCase = true;
/* 365 */     boolean nexteCharIsUpperCase = true;
/* 366 */     for (int i = 0; i < str.length(); i++) {
/* 368 */       char c = str.charAt(i);
/* 369 */       if (i > 0) {
/* 371 */         preCharIsUpperCase = Character.isUpperCase(str.charAt(i - 1));
/*     */       } else {
/* 375 */         preCharIsUpperCase = false;
/*     */       } 
/* 378 */       curreCharIsUpperCase = Character.isUpperCase(c);
/* 380 */       if (i < str.length() - 1)
/* 382 */         nexteCharIsUpperCase = Character.isUpperCase(str.charAt(i + 1)); 
/* 385 */       if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase) {
/* 387 */         sb.append('_');
/* 389 */       } else if (i != 0 && !preCharIsUpperCase && curreCharIsUpperCase) {
/* 391 */         sb.append('_');
/*     */       } 
/* 393 */       sb.append(Character.toLowerCase(c));
/*     */     } 
/* 396 */     return sb.toString();
/*     */   }
/*     */   
/*     */   public static boolean inStringIgnoreCase(String str, String... strs) {
/* 408 */     if (str != null && strs != null)
/* 410 */       for (String s : strs) {
/* 412 */         if (str.equalsIgnoreCase(trim(s)))
/* 414 */           return true; 
/*     */       }  
/* 418 */     return false;
/*     */   }
/*     */   
/*     */   public static String lastStringDel(String str, String spit) {
/* 430 */     if (!isEmpty(str) && str.endsWith(spit))
/* 432 */       return str.subSequence(0, str.length() - 1).toString(); 
/* 434 */     return str;
/*     */   }
/*     */   
/*     */   public static String convertToCamelCase(String name) {
/* 445 */     StringBuilder result = new StringBuilder();
/* 447 */     if (name == null || name.isEmpty())
/* 450 */       return ""; 
/* 452 */     if (!name.contains("_"))
/* 455 */       return name.substring(0, 1).toUpperCase() + name.substring(1); 
/* 458 */     String[] camels = name.split("_");
/* 459 */     for (String camel : camels) {
/* 462 */       if (!camel.isEmpty()) {
/* 467 */         result.append(camel.substring(0, 1).toUpperCase());
/* 468 */         result.append(camel.substring(1).toLowerCase());
/*     */       } 
/*     */     } 
/* 470 */     return result.toString();
/*     */   }
/*     */   
/*     */   public static String toCamelCase(String s) {
/* 479 */     if (s == null)
/* 481 */       return null; 
/* 483 */     if (s.indexOf('_') == -1)
/* 485 */       return s; 
/* 487 */     s = s.toLowerCase();
/* 488 */     StringBuilder sb = new StringBuilder(s.length());
/* 489 */     boolean upperCase = false;
/* 490 */     for (int i = 0; i < s.length(); i++) {
/* 492 */       char c = s.charAt(i);
/* 494 */       if (c == '_') {
/* 496 */         upperCase = true;
/* 498 */       } else if (upperCase) {
/* 500 */         sb.append(Character.toUpperCase(c));
/* 501 */         upperCase = false;
/*     */       } else {
/* 505 */         sb.append(c);
/*     */       } 
/*     */     } 
/* 508 */     return sb.toString();
/*     */   }
/*     */   
/*     */   public static boolean matches(String str, List<String> strs) {
/* 520 */     if (isEmpty(str) || isEmpty(strs))
/* 522 */       return false; 
/* 524 */     for (String pattern : strs) {
/* 526 */       if (isMatch(pattern, str))
/* 528 */         return true; 
/*     */     } 
/* 531 */     return false;
/*     */   }
/*     */   
/*     */   public static boolean isMatch(String pattern, String url) {
/* 546 */     AntPathMatcher matcher = new AntPathMatcher();
/* 547 */     return matcher.match(pattern, url);
/*     */   }
/*     */   
/*     */   public static <T> T cast(Object obj) {
/* 553 */     return (T)obj;
/*     */   }
/*     */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\lib\creditorRights-common-4.7.0.jar!\com\cr\commo\\utils\StringUtils.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */